<!doctype html>
<html lang="zh-cmn">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="./src/assets/boxy.png" />
    <meta name="description" content="PHP助手 是一款基于 Boxy-Google Blockly 的图形化代码编辑器。" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="theme-color" content="#4062f6" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="x5-fullscreen" content="true" />
    <meta name="fullscreen" content="yes" />
    <title>PHP助手</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
    <script>
      
      function handleIconClick() {
  Blockly.hideChaff()
}

function handleReadFile(name){
  var url = "./api.php";
  var data = {
      mode: 'read',
      name: name
  };
  
  fetch(url, {
      method: 'POST',
      body: JSON.stringify(data),
      headers: {
          'Content-Type': 'application/json'
      }
  })
  .then(function(response) {
      return response.json();
  })
  .then(function(x) {
      console.log(x);
      Blockly.serialization.workspaces.load(x, store.workspaceSvg);
  })
  .catch(function(error) {
      console.error(error);
  });
  
}

function handleSaveToCloud() {
  var phph_name = ''
  const json = Blockly.serialization.workspaces.save(store.workspaceSvg)
  const text = JSON.stringify(json)
  var result = prompt("请输入你的名字", file_name);
  
  if (result === null) {
    console.log("用户点击了取消按钮");
    phph_name = 'project'
  } else {
    phph_name = result
  }
  var file_name = phph_name
  var url = "./api.php";
  var data = {
      // 请求体数据
      mode:'save',
      code:text,
      name:phph_name
  };
  axios.post(url,JSON.stringify(data))
    .then((x)=>{
      console.log(x.data)
    })
  /*fetch(url, {
      method: "POST",
      headers: {
          "Content-Type": "application/x-www-form-urlencoded"
      },
      body: JSON.stringify(data)
  })
  .then(function(response) {
      return response.json();
  })
  .then(function(data) {
      console.log(data);
  })
  .catch(function(error) {
      console.log(error);
  });
  */
}


function handleReadCloud(){
  var url = "./api.php";
  var data = {
      // 请求体数据
      mode:'list',
  };
  axios.post(url,JSON.stringify(data))
    .then((x)=>{
      console.log(x.data)
      openFullscreen(x.data)
    })
  
}
      </script>
  </body>
</html>
